<template>
  <div class="app-container">
    <!-- 顶部控制台 -->
    <div class="filter-container">
      <el-input class="filter-item" style="width: 200px; margin-left: 0px" size="mini" placeholder="反馈内容" v-model="form.searchTitle"/>
      <el-select class="filter-item" style="width: 160px" size="mini" v-model="form.searchType" @change="handlePageInit">
        <el-option v-for="item in pageData.searchTypeList" :key="item.value" :label="item.label" :value="item.value"/>
      </el-select>
      <el-select class="filter-item" style="width: 120px" size="mini" v-model="form.searchStatus" @change="handlePageInit">
        <el-option v-for="item in pageData.searchStatusList" :key="item.value" :label="item.label" :value="item.value"/>
      </el-select>
      <el-button type="primary" size="mini" icon="el-icon-search" @click="handlePageInit">搜索</el-button>
    </div>
    <!-- 页面数据列表 -->
    <div class="data-table">
      <el-table :data="responseData.tableList"
                border style="width: 100%;"
                v-loading="pageData.loading"
                element-loading-text="拼命加载中"
                element-loading-spinner="el-icon-loading"
                element-loading-background="rgba(0, 0, 0, 0.8)"
                :header-cell-style="{ background: '#545C64', color: '#ffffff' }"
                @selection-change="handleTableSelection">
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column fixed="left" prop="feedbackId" label="反馈ID" width="320" align="center"/>
        <el-table-column prop="feedbackUser" label="反馈用户" width="320" align="center"/>
        <el-table-column prop="feedbackPlat" label="反馈来源" width="120" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.feedbackPlat === 1"><el-tag type="success">IOS</el-tag></span>
            <span v-if="scope.row.feedbackPlat === 2"><el-tag type="primary">Android</el-tag></span>
          </template>
        </el-table-column>
        <el-table-column prop="feedbackResolveStatus" label="处理状态" width="120" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.feedbackResolveStatus === 0"><el-tag type="warning">未处理</el-tag></span>
            <span v-if="scope.row.feedbackResolveStatus === 1"><el-tag type="success">已处理</el-tag></span>
          </template>
        </el-table-column>
        <el-table-column prop="feedbackContent" label="反馈内容" width="320" align="center"/>
        <el-table-column prop="feedbackCreateTime" label="反馈时间" width="320" align="center"/>
        <el-table-column fixed="right" label="操作" width="220" align="center">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="handleOpenDisposePage(scope)">回复</el-button>
            <el-button size="mini" type="danger" @click="handleDeleteData(scope)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!--分页器-->
    <div style="margin-top: 20px">
      <div class="block" style="width: 100%; text-align: center">
        <el-pagination
          layout="total, sizes, prev, pager, next, jumper"
          :current-page="form.pageNum"
          :page-size="form.pageSize"
          :total="form.total"
          :page-sizes="[12, 50, 100, 200]"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange">
        </el-pagination>
      </div>
    </div>
    <!-- 反馈处理 -->
    <el-dialog title="反馈处理" :visible.sync="pageData.disposePanelStatus" size="small"
               :before-close="handleCloseDisposePage">
      <el-form ref="form.disposeData" :model="form.disposeData" label-width="120px">
        <el-form-item label="反馈ID">
          <el-input v-model="form.disposeData.feedbackId" disabled></el-input>
        </el-form-item>
        <el-form-item label="反馈标题">
          <el-input v-model="form.disposeData.feedbackContent" disabled></el-input>
        </el-form-item>
        <el-form-item label="提交处理">
          <el-input v-model="form.disposeData.disposeContent"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleSaveButtonClick">保存反馈处理数据</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
  // 组件引入
  // 方法工具引入
  import { PermissionsToDetectFormUser } from '@/utils/PermissionsDetect';
  import { getPermission } from '@/utils/UserCookies';
  // 接口引入
  import { loadCmsFeedbackList,saveCmsFeedbackDisposeData } from "@/api/config";
  export default {
    name: "feedback",
    //import引入的组件需要注入到对象中才能使用
    components: {},
    data() {
      return {
        pageData:{
          searchTypeList: [
            {label: "反馈来源", value: -1},
            {label: "IOS", value: 1},
            {label: "Android", value: 2}
          ],
          searchStatusList: [
            {label: "处理状态", value: -1},
            {label: "已处理", value: 1},
            {label: "未处理", value: 0},
          ],
          loading: false,
          disposePanelStatus: false
        },// 页面配置数据
        form:{
          searchTitle: "",
          searchType: -1,
          searchStatus: -1,
          pageNum: 1,
          pageSize: 12,
          total: 0,
          selection: [],
          disposeData: {
            feedbackId: "",
            feedbackContent: "",
            disposeContent: "",
          }
        },// 页面表单
        formRules: {},// 表单验证
        responseData: {
          tableList: []
        },// 接口响应数据
      }
    },
    //监听属性 类似于data概念
    computed: {},
    //监控data中的数据变化
    watch: {},
    //方法集合
    methods:{
      // 事件函数
      handlePageInit(){
        this.form.pageNum = 1;
        this.pageData.loading = true;// 创建加载窗口
        this.loadCmsFeedbackList();// 读取路由角色列表
      },// 页面初始化事件
      handleCurrentChange(val){
        this.form.pageNum = val;// 更换页码
        this.pageData.loading = true;// 创建加载窗口
        this.loadCmsFeedbackList();// 读取路由角色列表
      },// 页码切换事件
      handleSizeChange(val){
        this.form.pageSize = val;// 更换页面大小
        this.pageData.loading = true;// 创建加载窗口
        this.loadCmsFeedbackList();// 读取路由角色列表
      },// 页面size切换事件
      handleTableSelection(val){
        let list = [];// 初始化多选数组
        for (let i=0; i<val.length; i++){
          list.push(val[i].id);
        }// 遍历多选的列表，将ID拼入数组中
        this.form.selection = list;// 进行多选值的切换
      },// 表格多选事件
      handleOpenDisposePage(scope){
        if (PermissionsToDetectFormUser(getPermission(), "530001")){
          if (scope.row.feedbackResolveStatus === 1){
            this.$message.warning("该反馈已被处理");
          }  else {
            // 初始化表单
            this.form.disposeData.feedbackId = scope.row.feedbackId;
            this.form.disposeData.feedbackContent = scope.row.feedbackContent;
            this.form.disposeData.disposeContent = "";
            // 打开面板
            this.pageData.disposePanelStatus = true;
          }
        } else {
          this.$message.warning('您的权限不足，无法使用此功能，请联系管理员');
        }
      },// 打开回复页面
      handleCloseDisposePage(){
        this.$confirm("确认关闭？").then(response => {
          // 初始化表单
          this.form.disposeData.feedbackId = "";
          this.form.disposeData.feedbackContent = "";
          this.form.disposeData.disposeContent = "";
          // 打开面板
          this.pageData.disposePanelStatus = false;
        }).catch(err => {
          console.log(err);
        });
      },// 关闭回复页面
      handleSaveButtonClick(){
        if (PermissionsToDetectFormUser(getPermission(), "530001")){
          this.$confirm('是否对此反馈内容进行回复, 请核对后继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.saveCmsFeedbackDisposeData();
          }).catch(close => {
            console.log(close);
            this.$message.info("已取消操作");
          });
        } else {
          this.$message.warning('您的权限不足，无法使用此功能，请联系管理员');
        }
      },// 保存反馈数据
      handleDeleteData(scope){
        this.$message.info("该功能暂未开放，如有需要请联系管理员");
      },// 删除内容数据
      // 接口
      loadCmsFeedbackList(){
        loadCmsFeedbackList(this.form).then(response => {
          if (response.code === "200"){
            this.pageData.loading = false;
            this.responseData.tableList = response.data.list;
            this.form.total = response.data.total;
          } else {
            this.$message.warning(response.message);
          }
        }).catch( error =>{
          console.log(error);
          this.$message.error(error);
        })
      },// 获取用户反馈列表
      saveCmsFeedbackDisposeData(){
        saveCmsFeedbackDisposeData(this.form.disposeData).then(response => {
          if (response.code === "200"){
            this.$message.success("保存成功");
            // 初始化表单
            this.form.disposeData.feedbackId = "";
            this.form.disposeData.feedbackContent = "";
            this.form.disposeData.disposeContent = "";
            // 关闭面板
            this.pageData.disposePanelStatus = false;
            this.handlePageInit();
          } else {
            this.$message.warning(response.message);
          }
        }).catch(error => {
          console.log(error);
          this.$message.error(error);
        })
      },// 保存反馈回复数据
    },
    //生命周期 - 创建完成（可以访问当前this实例）
    created: function () {
      let _this = this;
      document.onkeydown = function(e) {
        if (!_this.pageData.loading) {
          let key = window.event.keyCode;
          if (key === 13) {
            _this.handlePageInit(); //此方法是当按下enter键后要做的动作。
          }
        }
      };
      setTimeout(function () {
        _this.handlePageInit();
      }, 800);
    },
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {},
    beforeCreate() {}, //生命周期 - 创建之前
    beforeMount() {}, //生命周期 - 挂载之前
    beforeUpdate() {}, //生命周期 - 更新之前
    updated() {}, //生命周期 - 更新之后
    beforeDestroy() {}, //生命周期 - 销毁之前
    destroyed() {}, //生命周期 - 销毁完成
    activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
  };
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>
